<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="../../lib/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../static/css/weadmin.css">
		<style>
			.form-wrap {
				padding: 10px;
			}
			select {
				width: 380px;
				height: 38px;
				line-height: 1.3;
				border-width: 1px;
				border-style: solid;
				border-color: #e6e6e6;
				background-color: #fff;
				border-radius: 2px;
			}
			.layui-form-item .layui-form-label{
				width: 110px;
			    padding: 8px 15px;
			    height: 38px;
			    line-height: 20px;
			    border-width: 1px;
			    border-style: solid;
			    border-radius: 2px 0 0 2px;
				border-color: #e6e6e6;
			    text-align: center;
			    background-color: #FBFBFB;
			    overflow: hidden;
			    white-space: nowrap;
			    text-overflow: ellipsis;
			    box-sizing: border-box;
			}
			.layui-form-item .layui-input-inline{
				width: 380px;
			}
		</style>
	</head>

	<body>
		<div class="form-wrap">																
			<form id="kpiItem_form" action="" method="post" class="layui-form layui-form-pane" enctype="multipart/form-data">
				<div class="layui-form-item">
					<label for="kpi_code" class="layui-form-label">
                        <span class="we-red">*</span>kpi编号
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="kpi_code" name="kpiCode" required="" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="kpi_name" class="layui-form-label">
                        <span class="we-red">*</span>kpi名称
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="kpi_name" name="kpiName" required="" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="note" class="layui-form-label">
                        备注
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="note" name="note" required="" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="sort_code" class="layui-form-label">
                        <span class="we-red">*</span>排序码
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="sort_code" name="sortCode" required="" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="type" class="layui-form-label">
                        <span class="we-red">*</span>类型
                    </label>
					<div class="layui-input-inline" style="width:100px;">
						<select id="type" name="type"  class="valid">
							<option value="1">行数据</option>
							<option value="0">列数据</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<label for="showOnHome" class="layui-form-label">
                        <span class="we-red">*</span>首页展示
                    </label>
					<div class="layui-input-inline" style="width:60px;">
						<select id="showOnHome" name="showOnHome"  class="valid">
							<option value="0">否</option>
							<option value="1">是</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<button class="layui-btn" lay-submit="" lay-filter="add">提交</button>
				</div>
			</form>
		</div>
		<script src="../../publicjs/jquery-1.8.0.min.js"></script>
		<script src="../../publicjs/smallkingutil.js"></script>
		<script src="../../lib/layui/layui.js"></script>
		<script type="text/javascript">
			layui.use(['form', 'layer'], function() {
				var form = layui.form,
					layer = layui.layer;
				// 先判断当前的操作是新增还是修改
				var id = commonUtil.getRequestParam("id");
				if (id){
					// 请求后台得到当前修改的kpi数据，将其显示在表单里
					var ajaxParam = {
						url : commonUtil.domain() +'/admin/wxwork/kpi/item/detail',
						data : {
							id : id
						}
					}
					// 发送ajax 提交表单数据
					ajaxUtil.post(ajaxParam, function(data) {
						if(data.code == 200){
							formUtil.setForm($('#kpiItem_form'), data.data);
							form.render("select");
						}else{
							layer.alert(data.msg);
						}
    				});
				}
				// 监听表单提交
				form.on('submit(add)', function(data) {
					var data = data.field;
					var url,msg;
					// 有id就是修改，没有id就是新增
					if(id){
						url = commonUtil.domain() +"/admin/wxwork/kpi/item/update";
						msg = "修改kpi";
						data.id = id;
					}else{
						url = commonUtil.domain() +"/admin/wxwork/kpi/item/insert";
						msg = "新增kpi";
					}
					var ajaxParam = {
						url : url,
						data : data
					}
					// 发送ajax 提交表单数据
					ajaxUtil.post(ajaxParam, function(data) {
						if(data.code == 200){
							layer.alert(msg + "成功", {
								icon: 6
							}, function() {
								// 刷新父级的用户表格
								var parentHtml = window.parent;
								parentHtml.kpiItemTable.refresh();
								// 关闭当前frame
								var index = parentHtml.layer.getFrameIndex(window.name);
								parentHtml.layer.close(index);
							});
						}else{
							layer.alert(data.msg);
						}
					});
					return false;
				});
			});
		</script>
	</body>
</html>